package com.yx.backstage.controller;


import com.yx.backstage.manager.UserManager;
import com.yx.backstage.model.param.UserMessageParam;
import com.yx.backstage.model.vo.UserMessageVo;
import com.yx.backstage.config.global.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author YangXiong
 * @since 2023-03-25
 */
@RestController
@Slf4j
@RequestMapping("/user-message")
@Api(tags = "用户信息接口")
public class UserMessageController {
    @Resource
    private UserManager userManager;

    @PostMapping("/page")
    @ApiOperation("用户列表查询")
    public CommonResult<List<UserMessageVo>> getPage(@RequestBody UserMessageParam param) {
        log.info("UserMessageController getPage info UserMessageParam={}", param);
        return userManager.getPage(param);
    }

    @PostMapping("/update/status")
    @ApiOperation("启用或者禁用用户")
    public CommonResult<Boolean> updateStatus(@RequestBody UserMessageParam param) {
        log.info("UserMessageController updateStatus info UserMessageParam={}", param);
        Boolean result = userManager.updateStatus(param);
        if (result) {
            return CommonResult.success(true);
        }
        return CommonResult.fail("启用或者禁用用户失败");
    }

    @PostMapping("/delete")
    @ApiOperation("删除用户")
    public CommonResult<Boolean> deleteUser(@RequestBody UserMessageParam param) {
        log.info("UserMessageController deleteUser info UserMessageParam={}", param);
        Boolean result = userManager.deleteUser(param);
        if (result) {
            return CommonResult.success(true);
        }
        return CommonResult.fail("删除失败");
    }
}

